<OBJECT classid="clsid:285A9058-12DF-4B1D-AEA1-0FD2412CC761" width="20" height="20" id="zkissonlinesmart" class="displayN">
</OBJECT>
<COMMENT style="display:None">
    <EMBED type="application/x-eskerplus"
        classid="clsid:285A9058-12DF-4B1D-AEA1-0FD2412CC761"
        codebase="ZKISSOnlineX.ocx"                
        width=20 height=20>
    </EMBED>
</COMMENT>

{% extends "data_opform.html" %}
{% load i18n %}

{% block form %}
{% autoescape off %}
{% if form.non_field_errors %}
    <tr><td>{{ form.non_field_errors }}</td></tr>
{% endif %}
{% endautoescape %}
{% endblock %}

{% block addjs %}

    if(!$.browser.msie)
    {
        alert(gettext("目前该功能仅支持IE系列及IE内核的浏览器，请更换！"));
        window.location.href = "/{{ request.surl }}video/ChannelMngPage/";            
    } 

    //为避免加载界面时还没有显示PIN等信息，使用该回调函数--darcy20110330
    var emp_id = new Array();
    function after_object_action()
    {
        $(".select_row").each(function(){
            if($(this).attr("checked"))
            {
                emp_id.push($(this).parents("tr").attr("data"));
            }
        });
    }
    function before_submit()
    {
        $.ajax({
            type: "POST",
            url: "/{{ request.surl }}personnel/GetData/?func=card_printing_info&emp_id="+ emp_id,
            dataType: "json",
            async: false,
            success: function(data)
            {
                if(data != "")
                {
                    var ret = 0;
                    ret = zkissonlinesmart.InitSmartLibrary();
                    if(ret == 0)
                    {
                        var strDeviceID = zkissonlinesmart.SmartComm_GetDeviceList(); 		
                        ret = zkissonlinesmart.SmartComm_OpenDevice(strDeviceID);
                        if(ret != 0)
                        {
                            //alert("open device failed" + ret);
                            alert(gettext("启动设备失败，错误码：" + ret));
                            return false;
                        }
                        
                        //alert("start open doc")
                        var doc_csd = "E:\\demo.csd";//后续需要改为变量，可配置
                        ret = zkissonlinesmart.Smart_OpenDocumentEx(doc_csd);
                        if(ret !=0)
                        {
                            alert("SmartComm_OpenDocumentEx device failed" + ret);
                            alert(gettext("打开模板文件失败，错误码：" + ret+" 模板文件为："+doc_csd));
                            return false;
                        }
                        for(i in data.emps)
                        {
                            ret = zkissonlinesmart.SmartComm_SetCardPrintingInfo(data.emps[i][0], data.emps[i][1], data.emps[i][2], "D:\\trunk\\units\\adms\\files\\"+data.photo)
                            if(ret != 0)
                            {
                                //alert("SmartComm_SetCardPrintingInfo="+ret);
                                alert(gettext("设置卡片信息失败，错误码：" + ret));
                                return false;
                            }
                            ret = zkissonlinesmart.SmartComm_Print();
                            if(ret !=0)
                            {
                                alert(gettext("打印失败，错误码：" + ret));
                                //alert("SmartComm_Print device failed" + ret);
                                return false;
                            }
                            //alert("after print")
                            //ret = zkissonlinesmart.SmartComm_DoPrint();
                            //if(ret !=0)
                            //{
                              //alert("SmartComm_DoPrint device failed" + ret);
                              //return false;
                           // }
                        }
                        zkissonlinesmart.SmartComm_CloseDocument();
                        zkissonlinesmart.SmartComm_CloseDevice();
                        return true;
                    }
                    else
                    {
                        //alert('-----InitSmartLibrary Error--ret=',ret);
                        alert(gettext("初始化库文件失败，错误码：" + ret));
                    }
                }
                else
                {
                    //alert('error');
                    alert(gettext("向服务器请求数据失败，错误码：" + ret));
                    return false;
                }
            },
            error: function(XMLHttpRequest, textStatus, errorThrown)
            {
                alert(gettext("服务器处理数据失败，请重试！错误码：")+"-623");
            }
        });
    }

{% endblock%}
